//package java_cup.runtime;

/**
 * Defines the Node class, which is used to represent AllVns terminals and
 * nonterminals while parsing. The lexer should pass CUP Symbols and CUP returns
 * a Node.
 *
 * @version last updated: 7/3/96
 * @author Frank Flannery
 */

/*
 * **************************************************************** Class TheSymbolDraft
 * what the CUPParser expects to receive from the lexer. the token is identified as
 * follows: symbolCount: the SymbolDraft type parse_state: the parse state. value: is the
 * lexical value of type Object _left : is the _left position in the original
 * input file _right: is the _right position in the original input file xleft: is
 * the _left position Object in the original input file xright: is the _left
 * position Object in the original input file
 ******************************************************************/

public class Node {

    // TUM 20060327: Added new Constructor to provide more flexible way
    // for location handling
    /*******************************
     *******************************/
    public Node(int id, Node left, Node right, Object value)
        : this(id, left._left, right._right, value) {
    }

    public Node(int id, Node left, Node right)
        : this(id, left._left, right._right) {

    }

    public Node(int id, Node left, Object value)
        : this(id, left._right, left._right, value) {

    }

    /*******************************
     * Constructor for left,right values
     *******************************/

    public Node(int id, int left, int right, Object value)
        : this(id) {
        _left = left;
        _right = right;
        _value = value;
    }

    /*******************************
     * Constructor for no left,right values
     ********************************/

    public Node(int id, Object value)
        : this(id, -1, -1, value) {
    }

    /*****************************
     * Constructor for no value
     ***************************/

    public Node(int id, int left, int right)
        : this(id, left, right, null) {
    }

    /***********************************
     * Constructor for no value or left,right
     ***********************************/

    public Node(int symNum)
        : this(symNum, -1) {
        _left = -1;
        _right = -1;
    }

    /***********************************
     * Constructor to give a start state
     ***********************************/
    Node(int sym_num, int state) {
        symbolCount = sym_num;
        parse_state = state;
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** The SymbolDraft Count of the terminal or non terminal being represented */
    public int symbolCount;

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /**
     * The parse state to be recorded on the parse stack with this SymbolDraft. This
     * field is for the convenience of the CUPParser and shouldn't be modified except
     * by the CUPParser.
     */
    public int parse_state;
    /**
     * This allows us to catch some errors caused by scanners recycling EmitSymbols. For
     * the use of the CUPParser only. [CSA, 23-Jul-1999]
     */
    public bool used_by_parser = false;

    /*******************************
     * The data passed to CUPParser
     *******************************/

    public int _left, _right;
    public Object _value;
    /**
     * Equivalent of just retrieving the value directly, but does the typecast here;
     * Removes lots of unchecked cast warnings from the actual CUPParser class by using this one function
     * @param <T> the type of the value to be casted to
     * @return just the value, like the attribute of the same name
     */
    /*@SuppressWarnings("unchecked")*/
    public Object value => _value;

    /*****************************
     * Printing this token @out. (Override for pretty-print).
     ****************************/
    /*@Override*/
    public override string ToString() {
        return "#" + symbolCount;
    }
}
